﻿package view.popup
{
    import com.core.*;
    import com.sh.game.global.*;
    import flash.events.*;
    import plugin.store.*;
    import uiresource.dialog.*;

    public class TiquYuanBaoGame extends NewTiQuYuanBaoUI implements IDialogUI
    {
        private var _minValue:int = 800;

        public function TiquYuanBaoGame()
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            this.initEvent();
            return;
        }// end function

        private function initEvent() : void
        {
            tqallBtn.addEventListener(MouseEvent.CLICK, this.onTiQuAll);
            fptqBtn.addEventListener(MouseEvent.CLICK, this.onFenPiTiQu);
            closeBtn.addEventListener(MouseEvent.CLICK, this.onClicked);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            ta_input.addEventListener(MouseEvent.CLICK, this.onInput);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function onInput(event:MouseEvent) : void
        {
            var _loc_2:* = int(ta_input.text);
            if (_loc_2 < this._minValue)
            {
                ta_input.text = this._minValue.toString() + "";
            }
            return;
        }// end function

        private function onTiQuAll(event:MouseEvent) : void
        {
            this.close();
            if (int(ModelProxy.getValue("data", "yuanbao")) == 0)
            {
                ModelProxy.change("movetips", "error", "余额不足");
                return;
            }
            StoreSender._5tiqu(int(ModelProxy.getValue("data", "yuanbao")));
            return;
        }// end function

        private function onFenPiTiQu(event:MouseEvent) : void
        {
            if (int(ta_input.text) < 800)
            {
                ModelProxy.change("movetips", "error", "至少提取800元宝");
            }
            else
            {
                StoreSender._5tiqu(int(ta_input.text));
            }
            this.close();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            this.visible = true;
            ModelProxy.change("data", "tiQuYuanBaoIsOpen", true);
            ModelProxy.change("mainui", "checkYuanBao", null);
            ta_input.text = String(this._minValue);
            txt_has.text = "您当前拥有<font color =\'#43b436\'> " + int(ModelProxy.getValue("data", "yuanbao")) + " </font>元宝未提取";
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            event.stopImmediatePropagation();
            return;
        }// end function

        private function onClicked(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            this.visible = false;
            ModelProxy.change("data", "tiQuYuanBaoIsOpen", false);
            ModelProxy.change("mainui", "checkYuanBao", null);
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            return;
        }// end function

    }
}
